// 引入 request 方法，假设 request 方法已经定义在某个工具文件中
import request from '/@/utils/request';
import { LoginInput, LoginPhoneInput, UserRegistrationInput } from '../models';
// 定义 API 路径枚举
enum Api {
    Login = '/Auth/login',
    Logout = '/Auth/logout',
    UserInfo = '/Auth/userInfo',
    RefreshToken = '/Auth/refreshToken',
    UnLockScreen = '/Auth/unLockScreen',
    Captcha = '/Auth/captcha',
    LoginPhone = '/Auth/loginPhone',
    UserRegistration = '/Auth/userRegistration',
    SwaggerCheckUrl = '/swagger/checkUrl',
    SwaggerSubmitUrl = '/swagger/submitUrl',
}

// 定义 API 方法
export const apiSysAuthLoginPost = (body: LoginInput) =>
    request({
        url: Api.Login,
        method: 'post',
        data: body,
    });

export const apiSysAuthLogoutPost = () =>
    request({
        url: Api.Logout,
        method: 'post',
    });

export const apiSysAuthUserInfoGet = () =>
    request({
        url: Api.UserInfo,
        method: 'get',
    });

export const apiSysAuthRefreshTokenGet = (accessToken?: string) =>
    request({
        url: `${Api.RefreshToken}${accessToken ? `?accessToken=${accessToken}` : ''}`,
        method: 'get',
    });

export const apiSysAuthUnLockScreenPost = (password: string) =>
    request({
        url: Api.UnLockScreen,
        method: 'post',
        params: { password },
    });

export const apiSysAuthCaptchaGet = () =>
    request({
        url: Api.Captcha,
        method: 'get',
    });

export const apiSysAuthLoginPhonePost = (body: LoginPhoneInput) =>
    request({
        url: Api.LoginPhone,
        method: 'post',
        data: body,
    });

export const apiSysAuthUserRegistrationPost = (body?: UserRegistrationInput) =>
    request({
        url: Api.UserRegistration,
        method: 'post',
        data: body,
    });

export const apiSwaggerCheckUrlPost = () =>
    request({
        url: Api.SwaggerCheckUrl,
        method: 'post',
    });

export const apiSwaggerSubmitUrlPostForm = (userName?: string, password?: string) => {
    const formData = new FormData();
    if (userName) formData.append('UserName', userName);
    if (password) formData.append('Password', password);
    return request({
        url: Api.SwaggerSubmitUrl,
        method: 'post',
        data: formData,
    });
};